# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-sphinx-prompt
pkgver=1.8.0
pkgrel=1
pkgdesc='Sphinx directive to add unselectable prompt'
arch=('any')
url='https://github.com/sbrunner/sphinx-prompt'
license=('BSD')
depends=(
  'python'
  'python-sphinx'
  'python-pygments'
  'python-docutils'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-wheel'
  'python-poetry-core'
)
_commit='adebec5cb63deea6e1a210d38e675304ee664ec2'
source=(
  "$pkgname::git+$url#commit=$_commit"
  'pyproject.toml-template.patch'
  'remove-unnecessary-dependencies.patch'
)
b2sums=('SKIP'
        'a5c11ccae6970584c0a533f0527a118ee68f9eee1db9acf3b0c7af6b1f82b8cf6071a04a279026396886d8c8645286a7abc7787aa4afa00136a1b9922463ecf7'
        '1552cd699b1f273f6bd0b6bf59ad23341285e645b28fee805f122b9babb7d6facb0b501825ae6f54be472b3325b7c07fa637d183c0f08ff8e15672056794e28b')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # manually set version
  patch -p1 -i "$srcdir/pyproject.toml-template.patch"

  # remove useless dependencies
  patch -p1 -i "$srcdir/remove-unnecessary-dependencies.patch"

  # WTF is wrong with Python developers
  # https://github.com/sbrunner/sphinx-prompt/commit/4e4638bd449e33ea737b704d867d4ee35d4d5ce3
  cp -r sphinx{_,-}prompt
}

build() {
  cd "$pkgname"

  # set version
  sed -e "s/@PKGVER@/$pkgver/" -i pyproject.toml

  python -m build --wheel --no-isolation
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  ln -s "$site_packages/sphinx_prompt-$pkgver.dist-info/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
